package nowember.test_11_2;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Solution {
    int maxSum = Integer.MIN_VALUE;
    List<Integer> maxPath = new ArrayList<>();
    public int[] pathSum (TreeNode root) {
        // write code here
        findMaxPath(root,new ArrayList<>());
        int[] res = new int[maxPath.size()];
        for (int i = 0; i < maxPath.size(); i++) {
            res[i] = maxPath.get(i);
        }
        return res;
    }
    public void findMaxPath(TreeNode node,List<Integer> currentPath) {
        if (node == null) {
            return;
        }
        currentPath.add(node.val);
        if (node.left == null && node.right == null) {
            int currentSum = 0;
            for(int num : currentPath) {
                currentSum += num;
            }
            if (currentSum > maxSum) {
                maxSum = currentSum;
                maxPath = new ArrayList<>(currentPath);
            }
        }
        findMaxPath(node.left, currentPath);
        findMaxPath(node.right, currentPath);
        currentPath.remove(currentPath.size() - 1);
    }
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();
    public void push(int node) {
        if(stack1.size() == 0) {
            stack1.push(node);
        } else {
            while(stack1.size() != 0) {
                stack2.push(stack1.pop());
            }
            stack1.push(node);
            while(stack2.size() != 0) {
                stack1.push(stack2.pop());
            }
        }
    }
    public int pop() {
        return stack1.pop();
    }
    //1.两个栈实现一个队列
    //2.一桶球 每次取一个或者三个，n个球有多少种取法
    public int numWays(int n) {
        if(n == 0) {
            return 0;
        }
        if(n <= 2) {
            return 1;
        }
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 1;
        dp[3] = 2;
        for (int i = 4; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 3];
        }
        return dp[n];
    }
}
